﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using HandyControl.Controls;
namespace AgileLogistics.View.Meishi.Partial
{
    /// <summary>
    /// Dialog.xaml 的交互逻辑
    /// </summary>
    public partial class Dialog : UserControl
    {
        public Dialog()
        {
            InitializeComponent();
            vm = this.DataContext as ViewModel.PollViewModel;
        }


        ViewModel.PollViewModel vm;
        private  void btn_Ok_Click(object sender, RoutedEventArgs e)
        {

            switch(vm.ClassID)
            {
                case 2:
                    AddZhucai();
                    break;
                case 3:
                    AddZhushi();
                    break;
                case 4:
                    AddTang();
                    break;
            }
           

                
             


            var d = HandyControl.Controls.Dialog.Show<Dialog>();
           // await Task.Delay(5 * 1000);
            d.Close();

        }



        private void AddZhucai()
        {
             
            foreach (Model.Menus item in trf.SelectedItems)
            {
                vm.ZhucaiMenu.Add(vm.MenuToPollItem(item));
            }
        }

        private void AddZhushi()
        {
            
            foreach (Model.Menus item in trf.SelectedItems)
            {
                vm.ZhushiMenu.Add(vm.MenuToPollItem(item));
            }
        }

        private void AddTang()
        {
            
            foreach (Model.Menus item in trf.SelectedItems)
            {
                vm.TangMenu.Add(vm.MenuToPollItem(item));
            }
        }


        Model.Repository<Model.Menus> MenuRep = new Model.Repository<Model.Menus>();
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
             
                vm.Menus =new System.Collections.ObjectModel.ObservableCollection<Model.Menus>( MenuRep.GetList().Where<Model.Menus>(m=>m.ClassId == vm.ClassID));
            
        }
    }
}
